package com.smz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smz.dao.TStaffDAO;
import com.smz.entity.PageEntity;
import com.smz.entity.TStaff;
import com.smz.service.TStaffService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TStaffServiceImpl extends ServiceImpl<TStaffDAO, TStaff> implements TStaffService {

    @Autowired
    private TStaffDAO tStaffDAO;


    @Override
    public PageEntity<TStaff> findTStaffsPage(Integer current) {
        int count = tStaffDAO.selectTStaffCount();//查询角色的总数
        //显示出来的页数
        int pageCount = count%PageEntity.PAGE_SIZE==0?count/PageEntity.PAGE_SIZE:PageEntity.PAGE_SIZE+1;
        //调用limit查询进行分页
        List<TStaff> tStaffs= tStaffDAO.selectTStaffByPage((current - 1) * PageEntity.PAGE_SIZE, PageEntity.PAGE_SIZE);
        return new PageEntity<>(tStaffs,count,current,pageCount);
    }

    @Override
    public List<TStaff> findAllTStaffsById(Integer id) {
        return tStaffDAO.selectAllTStaffById(id);
    }

    @Override
    public TStaff findTStaffById(Integer id) {
        return tStaffDAO.selectTStaffById(id);
    }

    @Override
    public IPage<TStaff> findTStaffByNameId(Integer start, Integer length, String name, Integer dId) {
        return tStaffDAO.selectTStaffByNameId(new Page<TStaff>(start,length),name,dId);
    }

    @Override
    public List<TStaff> findAllTStaffs() {
        return tStaffDAO.selectAllTStaffs();
    }

    @Override
    public void modifyTStaffById(Integer id, String accountStatus) {
        tStaffDAO.updateTStaffById(id,accountStatus);
    }


}
